package zhongbo.java.air.dictionary.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhongbo.java.air.dictionary.exception.BusinessException;
import zhongbo.java.air.dictionary.exception.ExceptionCode;
import zhongbo.java.air.dictionary.mapper.AirAlertZoneMapper;
import zhongbo.java.air.dictionary.mapper.AirPortMapper;
import zhongbo.java.air.dictionary.model.AirAlertZone;
import zhongbo.java.air.dictionary.model.AirPort;
import zhongbo.java.air.dictionary.service.IAirAlertZoneService;
import zhongbo.java.air.dictionary.vo.PageVo;

@Service
public class AirAlertZoneServiceImpl implements IAirAlertZoneService {
    @Autowired
    AirAlertZoneMapper airAlertZoneMapper;

    @Override
    public int addAir(AirAlertZone airAlertZone) {
        airAlertZone.setId(null);
        if (airAlertZone == null && airAlertZone.equals("")){
            throw new BusinessException(ExceptionCode.AIRALERTZONE_NULL);
        }
        int add = airAlertZoneMapper.insert(airAlertZone);
        return add;
    }

    @Override
    public void delete(String id) {
        if (id ==null && id.equals("")){
            throw new BusinessException(ExceptionCode.ID_NULL);
        }
        airAlertZoneMapper.deleteById(id);
    }

    @Override
    public int update(AirAlertZone airAlertZone) {
        if (airAlertZone == null && airAlertZone.equals("")){
            throw new BusinessException(ExceptionCode.AIRALERTZONE_NULL);
        }

        int update = airAlertZoneMapper.updateById(airAlertZone);

        return update;
    }

    @Override
    public AirAlertZone selectById(String id) {
        if (id == null && id.equals("")){
            throw new BusinessException(ExceptionCode.ID_NULL);
        }
        AirAlertZone airAlertZone = airAlertZoneMapper.selectById(id);
        return airAlertZone;
    }

    @Override
    public PageVo page(String zoneCode, Integer pageNumber, Integer pageSize) {
        QueryWrapper<AirAlertZone> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(zoneCode)){
            queryWrapper.like("zone_code",zoneCode);
        }
        IPage<AirAlertZone> pageParam = new Page<>(pageNumber,pageSize);
        IPage<AirAlertZone> AirIPage = airAlertZoneMapper.selectPage(pageParam,queryWrapper);
        return new PageVo<>(AirIPage);
    }


}
